


//
//  VideoViewController.m
//  NeiHanDemo
//
//  Created by qianfeng on 16/2/19.
//  Copyright © 2016年 王卓越. All rights reserved.
//

#import "VideoViewController.h"
#import "Define.h"
#import "VideoModel.h"
#import "VideoTableViewCell.h"
#import "PlayViewController.h"

@interface VideoViewController ()

@end

@implementation VideoViewController

//重写init方法，在方法中标识自己的类别
- (id)init{
    if (self = [super init]) {
        self.category = VIDEOS;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

//子类重写父类的方法，以满足自己的需求
- (void)registTableViewCell{
    //bundle: ->main  bundle
    UINib *nib = [UINib nibWithNibName:@"VideoTableViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"cellID"];
}

//解析数据
-(void)parseResponseData:(NSDictionary *)dic{
    NSArray *array = dic[@"items"];
    for (NSDictionary *itemDic in array) {
        VideoModel *model = [[VideoModel alloc] init];
        [model setValuesForKeysWithDictionary:itemDic];
        [self.dataSource addObject:model];
    }
}

//记录最后一个条目的时间
- (void)recordLastUpdateTime{
    VideoModel *model = [self.dataSource lastObject];
    self.max_timeStmp = model.update_time;
}

#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    VideoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
    VideoModel *model = [self.dataSource objectAtIndex:indexPath.row];
    [cell updateUIWithModel:model];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

//注意 是   didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
//    不是  didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    VideoModel *model = [self.dataSource objectAtIndex:indexPath.row];
    NSString *videoUrl = model.vplay_url;
    PlayViewController *playVC = [[PlayViewController alloc] init];
    playVC.videoUrl = videoUrl;
    //当推进下一个界面的时候，是否隐藏下个界面下方的 BottomBar
    playVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:playVC animated:YES];
}

@end
